#include<iostream>
#include <string>
#include <queue>
using namespace std;
typedef struct node{
    char data;
    struct node *lchild;
    struct node *rchild;
}BTNode;
typedef struct node *BTree;
int GetHeight( BTree BT );
BTree CreateBT(char *pre,char *in,int n);
int main()
{
	BTree BT;
	int n;
	cin>>n;
	char pre[n];
	char in[n];
	cin>>pre>>in;
	BT=CreateBT(pre,in,n);
	cout<<GetHeight( BT );
} 
BTree CreateBT(char *pre,char *in,int n){
	BTree b;
	char *p;
	int k;
	if(n<=0)return NULL;
	b=new BTNode;
	b->data=*pre;
	for(p=in;p<in+n;p++)
		if(*p==*pre)
			break;
	k=p-in;
	b->lchild=CreateBT(pre+1,in,k);
	b->rchild=CreateBT(pre+k+1,p+1,n-k-1);
	return b;
}
int GetHeight( BTree BT ){
	int lth,rth;
	if(BT==NULL)return 0;
	else {
		lth=GetHeight(BT->lchild);
		rth=GetHeight(BT->rchild);
		return (lth>rth)?(lth+1):(rth+1);
	}
}
